package cn.edu.scau.cmi.xuchuangxiong.client;

import java.util.ArrayList;
import java.util.List;

import cn.edu.scau.cmi.xuchuangxiong.adapter.SortAdapterOfClass;
import cn.edu.scau.cmi.xuchuangxiong.adapter.SortTarget;
import cn.edu.scau.cmi.xuchuangxiong.adapter.Student;
import javafx.application.Application;
import javafx.event.ActionEvent;
import javafx.event.EventHandler;
import javafx.geometry.Insets;
import javafx.geometry.Pos;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.Label;
import javafx.scene.control.TextArea;
import javafx.scene.control.TextField;
import javafx.scene.layout.GridPane;
import javafx.scene.text.Text;
import javafx.stage.Stage;

public class ClassAdapterClient extends Application implements EventHandler<ActionEvent> {
	Label idLabel = new Label("学号：");
	Label nameLabel = new Label("姓名：");
	TextField idTextField = new TextField(); //学号输入框
	TextField nameTextField = new TextField(); //姓名输入框
	Button button = new Button("添加");
	GridPane layout = new GridPane(); //布局
	TextArea output = new TextArea("");
	List<Student> sl = new ArrayList<Student>();
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage primaryStage) throws Exception {
		
		primaryStage.setTitle("类适配器");
		layout.setAlignment(Pos.CENTER);
		layout.setHgap(10);
		layout.setVgap(10);
		layout.setPadding(new Insets(25, 25, 25, 25));
		layout.add(idLabel,0,0); //将控件添加入布局
		layout.add(idTextField,1,0);
		layout.add(nameLabel, 0, 1);
		layout.add(nameTextField, 1, 1);
		layout.add(button, 0, 2);
		layout.add(output, 1, 3);
		button.setOnAction(this);//绑定事件
		Scene scene = new Scene(layout,700,300); //设置布局、大小
		primaryStage.setScene(scene); //将场景添加到stage
		primaryStage.show(); //显示stage
		
	}


	@Override
	public void handle(ActionEvent event) {
		output.clear();
		Student s = new Student();
		s.setId(Integer.parseInt(idTextField.getText()));
		s.setName(nameTextField.getText());
		sl.add(s);
		SortTarget st = new SortAdapterOfClass();
		sl = st.sortStudent(sl);
		for(Student ts : sl)
		{
			output.appendText(ts.toString()+"\n");
		}
		
	}

}
